package com.itlong.cloud.property.service.impl;

import com.itlong.cloud.POJO.DTO.operate.ParkingRecordPageDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyMonthCardPaymentRecordGetPageDTO;
import com.itlong.cloud.POJO.VO.property.PropertyMonthCardPaymentRecordGetPageVO;
import com.itlong.cloud.POJO.VO.property.PropertyTemporaryCarFeeRecordVO;
import com.itlong.cloud.property.dao.IPropertyParkingFeeRecordDao;
import com.itlong.cloud.property.service.IPropertyParkingFeeRecordService;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      物业-智慧停车-停车缴费记录接口实现类.
 * </desc>
 *
 * @createDate 2018/11/5
 */
@Service
public class PropertyParkingFeeRecordServiceImpl implements IPropertyParkingFeeRecordService {

    @Autowired
    IPropertyParkingFeeRecordDao iPropertyParkingFeeRecordDao;

    /**
     * <desc>
     *      临时车缴费记录分页查询
     * <desc/>
     *
     * @param feeRecordDTO 分页查询参数
     * @return 标准返回结果
     * @author Juguang.S
     * @createDate 2018/11/5
     */
    @Override
    public Page<PropertyTemporaryCarFeeRecordVO> getTemporaryCarFeeRecordPage(ParkingRecordPageDTO feeRecordDTO) throws Exception {
        //将DTO转换为Map
        Map<String,Object> params = SqlUtil.convertBeanToMapParams(feeRecordDTO);
        //分页默认pageSize为20
        Page<PropertyTemporaryCarFeeRecordVO> page = new Page<>();
        page.getPage().setPageSize(feeRecordDTO.getPageSize());
        page.getPage().setCurrentPage(feeRecordDTO.getCurrentPage());
        params.put("currentPage",page.getPage().getStartSlip());
        params.put("pageSize",page.getPage().getPageSize());
        List<PropertyTemporaryCarFeeRecordVO> list = iPropertyParkingFeeRecordDao.getTemporaryCarFeeRecordPage(params);
        Integer count = iPropertyParkingFeeRecordDao.getTemporaryCarFeeRecordCount(params);
        page.setRows(list,count);
        return page;
    }

    /**
     * <desc>
     *      月卡缴费记录分页查询
     * <desc/>
     *
     * @param propertyMonthCardPaymentRecordGetPageDTO 分页查询参数
     * @return 分页结果
     * @author wangzhi
     * @createDate 2018/11/08
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Page<PropertyMonthCardPaymentRecordGetPageVO> getMonthCardPaymentRecordPage(PropertyMonthCardPaymentRecordGetPageDTO propertyMonthCardPaymentRecordGetPageDTO) throws Exception {
        Map<String,Object> params = SqlUtil.convertBeanToMapParams(propertyMonthCardPaymentRecordGetPageDTO);
        Page<PropertyMonthCardPaymentRecordGetPageVO> page = new Page<>();
        page.getPage().setPageSize(propertyMonthCardPaymentRecordGetPageDTO.getPageSize());
        page.getPage().setCurrentPage(propertyMonthCardPaymentRecordGetPageDTO.getCurrentPage());
        params.put("startSlip",page.getPage().getStartSlip());
        params.put("pageSize",page.getPage().getPageSize());
        List<PropertyMonthCardPaymentRecordGetPageVO> propertyMonthCardPaymentRecordGetPageVOS = iPropertyParkingFeeRecordDao.getMonthCardPaymentRecordPage(params);
        Integer count = iPropertyParkingFeeRecordDao.getMonthCardPaymentRecordCount(params);
        page.setRows(propertyMonthCardPaymentRecordGetPageVOS,count);
        return page;
    }
}